(function($, gmwk) {

  // jQuery extensions
  
  /** 
   * @description Convert the output of serializeArray to key = value
   *   http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery
   * @public
   * @returns {Object} Serialized object
   **/
  $.fn.serializeObject = function() {
      var Obj = {};
      var aSerialized = this.serializeArray();
      $.each(
          aSerialized,
          function() {
              if (Obj[this.name]) {
                  if (!Obj[this.name].push) {
                      Obj[this.name] = [Obj[this.name]];
                  }
                  Obj[this.name].push(this.value || '');
              } else {
                  Obj[this.name] = this.value || '';
              }
          }
      );
      return Obj;
  };

  // Utility functions
  
  gmwk.utils.objectLength = function(Obj) {
      var nSize = 0;
      for (var sKey in Obj) {
          nSize++;
      }
      return nSize;    
  }
    
  // TODO: Does not support nested objects or arrays, could also be more efficient
  gmwk.utils.compareObjects = function(Obj1, Obj2) {
      var nLen1 = gmwk.utils.objectLength(Obj1);
      var nLen2 = gmwk.utils.objectLength(Obj2);
      if (nLen1 != nLen2) {
          return false;
      }
      for (key in Obj1) {
          if (Obj1[key] !== Obj2[key]) {
              return false;
          }
      }
      return true;
  }

})(jQuery, window.gmwk);
